﻿using Com.Enemy.EnemySystem.EnemyLifecycle;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Player.Weapons.Wands
{
    public class PlayerBulletBodyBase:BulletBody
    {
        [Header("弹幕特效")]
        [SerializeField]
        GameObject defaultStyle;
        [SerializeField]
        GameObject fireStyle;
        [SerializeField]
        GameObject waterStyle;
        [SerializeField]
        GameObject fire_waterStyle;
        [SerializeField]
        GameObject earthStyle;
        [SerializeField]
        GameObject electricStyle;

        [Header("击中特效")]
        [SerializeField]
        GameObject hitStyle;


        public bool isMoveSelf = true;

        public void Init(List<Core> Cores,BulletData bulletData,TimeData timeData,Dictionary<Type,int> types)
        {
            foreach (var core in Cores)
            {

                if (core == Core.Fire)
                    fireStyle.SetActive(true);
                else if (core == Core.Water)
                    waterStyle.SetActive(true);
                else if (core == Core.Earth)
                {
                    earthStyle.SetActive(true);
                    defaultStyle.SetActive(false);
                }                 
                else if (core == Core.Electric)
                    electricStyle.SetActive(true);
            }
            if (fireStyle.activeSelf && waterStyle.activeSelf)
            {
                fireStyle.SetActive(false);
                waterStyle.SetActive(false);
                fire_waterStyle.SetActive(true);
            }
            BaseInit(bulletData, timeData, types);
        }

        private void Update()
        {
            if (!isMoveSelf)
                return;
            transform.Translate(Vector2.up * bulletData.BulletSpeed*Time.deltaTime*timeData.LocalTimeScale);
            Destroy(gameObject, bulletData.BulletLifeTime*timeData.LocalTimeScale);
        }



        private void OnTriggerEnter(Collider other)
        {
            if (other.tag == "Enemy")
            {
                hitStyle.SetActive(true);
                other.gameObject.GetComponent<EnemyBody>().TakeDamage(1, bulletData.Atk, bulletData.BulletForce);
                Destroy(gameObject, 3f);
            }
        }
    }   

    

}
